#include "./myApplication.h"

namespace Framework
{
	

	Sky::NType::TBool myApplication::Initialise( Handler::Handle proc )
	{
		m_EventManager.setEventCallBack(proc);
		m_Managers.setRoot(this);
		m_Managers.attachFirstChildOf(this,TreeManager::cast(&m_EventManager));
		m_Managers.attachNextSiblingOf(TreeManager::cast(&m_EventManager),TreeManager::cast(&m_ResManager));
		m_Managers.attachNextSiblingOf(TreeManager::cast(&m_ResManager),TreeManager::cast(&m_WinManager));
		return vTrue;
	}

	Sky::NValue::MsgStatus myApplication::handleSendEvent( myEventManager* manager,Message* event )
	{
		if(vIntercepted == onSendEvent(manager,event))
			return vIntercepted;
		if(event->isKindOf(myAppMessage::Class))
		{
			if(vIntercepted == (this->*event->getEvent())(manager,event))
				return vIntercepted;
		}
		return vContinue;
	}

	Sky::NValue::MsgStatus myApplication::onSendEvent( myEventManager* sender,Message* event )
	{
		if(event->isKindOf(myWindowletMessage::Class))
		{
			if(vIntercepted == m_WinManager.handleSendEvent(sender,event))
			return vIntercepted;
		}
		return vContinue;
	}

	Sky::NValue::MsgStatus myApplication::handleInput( myEventManager* manager,Message* event )
	{
		if(vIntercepted == onInput(manager,event))return vIntercepted;
		return invokeHandler(manager,event);
	}

	Sky::NValue::MsgStatus myApplication::onInput( myEventManager* manager,Message* event )
	{
		return vContinue;
	}

	Sky::NValue::MsgStatus myApplication::handleDeleted( myEventManager* manager,Message* event )
	{
		if(vIntercepted == onDeleted(manager,event))return vIntercepted;
		return invokeHandler(manager,event);
	}

	Sky::NValue::MsgStatus myApplication::onDeleted( myEventManager* sender,Message* event )
	{
		return vContinue;
	}

}